package com.air.ota.vo;

import com.air.ota.util.ConfigProperties;
import com.air.ota.util.HexStringUtil;
import com.air.ota.util.PBOCUtil;
import com.air.ota.util.PkgUtil;

public class UTKCancelInitUplinkVO extends UTKBaseUplinkPgkVO {
	
	protected byte[] cardAppSequence;
	protected byte[] passwordEnc;
	protected byte[] cancelSequence;
	protected byte   keyIndex;
	protected byte[] cardRandom;
	protected byte[] ewalletTransSequence;
	protected byte[] ewalletRemain;
	protected byte[] amount;
	protected byte   transTypeTag;
	protected byte[] terminalCode;
	protected byte[] lastTransData;
	protected byte[] cardDeposit;
	protected byte   cardType;
	protected byte   syncCount;
	protected byte[] syncTransDataList;
	protected byte[] pkgSequence;
	
	protected String password;
	
	public UTKCancelInitUplinkVO(byte[] cardSequence){
		super();
		this.cardSequence = cardSequence;
		
		cardAppSequence = new byte[8];
		cancelSequence= new byte[2];
		cardRandom = new byte[4];
		ewalletTransSequence = new byte[2];
		ewalletRemain = new byte[4];
		amount = new byte[4];
		terminalCode = new byte[6];
		lastTransData= new byte[23];
		cardDeposit = new byte[4];
		
		pkgSequence = new byte[4];
		
		
		passwordEnc =  new byte[8];
	}
	
	public void parse(byte[] pkg){
		super.parse(pkg);
		super.decryptCmdData();
		
		
		
		System.arraycopy(cmdData, 0, cardAppSequence, 0, 8);
		System.arraycopy(cmdData, 8, this.passwordEnc, 0, 8);
		System.arraycopy(cmdData, 16, cancelSequence, 0, 2);
		keyIndex= cmdData[18];
		System.arraycopy(cmdData, 19, this.cardRandom, 0, 4);
		System.arraycopy(cmdData, 23, this.ewalletTransSequence, 0, 2);
		System.arraycopy(cmdData, 25, this.ewalletRemain, 0, 4);
		System.arraycopy(cmdData, 29, this.amount, 0, 4);
		this.transTypeTag = cmdData[33];
		System.arraycopy(cmdData, 34, this.terminalCode, 0, 6);
		//terminalCode = HexStringUtil.hexStringToBytes(ConfigProperties.getInstance().getValue("szt.terminalNum"));
		
		System.arraycopy(cmdData, 40, this.lastTransData, 0, 23);
		System.arraycopy(cmdData, 63, this.cardDeposit, 0, 4);
		this.cardType = cmdData[67];
		this.syncCount = cmdData[68];
		
		int syncTransLength = syncCount*14;
		syncTransDataList = new byte[syncTransLength];
		System.arraycopy(cmdData, 69, this.syncTransDataList, 0, syncTransLength);
		System.arraycopy(cmdData, 69+syncTransLength, this.pkgSequence, 0, 4);
		
		PBOCUtil pboc = new PBOCUtil();
		this.password = HexStringUtil.bytesToHexString(pboc.TripleDes(this.UTKSessionKey, this.passwordEnc, 0));
		
		
		PkgUtil.setCurrentPkgSequence(pkgSequence);
	}
	
	public byte[] getCardAppSequence() {
		return cardAppSequence;
	}

	public byte[] getCancelSequence() {
		return cancelSequence;
	}

	public byte getKeyIndex() {
		return keyIndex;
	}

	public byte[] getCardRandom() {
		return cardRandom;
	}

	public byte[] getEwalletTransSequence() {
		return ewalletTransSequence;
	}

	public byte[] getEwalletRemain() {
		return ewalletRemain;
	}

	public byte[] getAmount() {
		return amount;
	}

	public byte getTransTypeTag() {
		return transTypeTag;
	}

	public byte[] getTerminalCode() {
		return terminalCode;
	}

	public byte[] getLastTransData() {
		return lastTransData;
	}

	public byte[] getCardDeposit() {
		return cardDeposit;
	}

	public byte getCardType() {
		return cardType;
	}

	public byte getSyncCount() {
		return syncCount;
	}

	public byte[] getSyncTransDataList() {
		return syncTransDataList;
	}

	public byte[] getPkgSequence() {
		return pkgSequence;
	}
	
	public String getPassword(){
		return this.password;
	}
	
}
